<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@include file="../head.jsp"%>
<html>
<head>
<script type="text/javascript">
(function(){
    Ext.onReady(function(){
        Ext.QuickTips.init();

        Ext.define('Instruction', {
            extend: 'Ext.data.Model',
            fields: [
                {name:'id',type:'string'},
                {name:'no',type:'string'},
                {name:'content',type:'int'},
                {name:'contentName',type:'string'},
                {name:'customerId',type:'string'},
                {name:'customerName',type:'string'},
                {name:'remark',type:'string'},
                {name:'startAirportId',type:'string'},
                {name:'startAirportName',type:'string'},
                {name:'endAirportId',type:'string'},
                {name:'endAirportName',type:'string'},
                {name:'cargoName',type:'string'},
                {name:'num',type:'int'},
                {name:'volume',type:'int'},
                {name:'weight',type:'int'},
                {name:'sizeDesc',type:'string'},
                {name:'flight',type:'string'},
                {name:'flightDateStr',type:'string'},
                {name:'depotIn',type:'int'},
                {name:'depotInName',type:'string'},
                {name:'depotInDesc',type:'string'},
                {name:'price',type:'int'},
                {name:'flag',type:'int'},
                {name:'flagName',type:'string'},
                {name:'bgDateStr',type:'string'},
                {name:'unit',type:'int'},
                {name:'unitName',type:'string'},
                {name:'creatorId',type:'string'},
                {name:'creatorName',type:'string'},
                {name:'createDateStr',type:'string'},
                {name:'status',type:'int'}
            ]
        });

        var no = Ext.create('Ext.form.field.Text',{});

        var customerCombo = Ext.create('Ext.form.ComboBox',{
            editable:false,
            queryMode: 'local',
            displayField: 'label',
            typeAhead:true,
            valueField: 'value',
            store:Ext.create('Ext.data.Store', {
                model: 'commonModel',
                proxy: {
                    type:'ajax',
                    url:'/fsxt/sysBase!getCustomer.action'
                },
                autoLoad: true,
                listeners:{
                    load:function(){
                        var insert = Ext.create('commonModel',{value:'',label:'0-全部'});
                        this.insert(0,insert);
                    }
                }
            })
        });

        var startAirport = Ext.create('Ext.form.ComboBox',{
            queryMode: 'local',
            displayField: 'label',
            typeAhead:true,
            valueField: 'value',
            forceSelection: true,
            selectOnFocus: true,
            triggerAction:'all',
            store:Ext.create('Ext.data.Store', {
                model: 'commonModel',
                proxy: {
                    type:'ajax',
                    url:'/fsxt/sysBase!getAirport.action'
                },
                autoLoad: true,
                listeners:{
                    load:function(){
                        var insert = Ext.create('commonModel',{value:'',label:'0-全部'});
                        this.insert(0,insert);
                    }
                }
            })
        });

        var endAirport = Ext.create('Ext.form.ComboBox',{
            queryMode: 'local',
            typeAhead:true,
            forceSelection: true,
            selectOnFocus: true,
            triggerAction:'all',
            displayField: 'label',
            valueField: 'value',
            store:Ext.create('Ext.data.Store', {
                model: 'commonModel',
                proxy: {
                    type:'ajax',
                    url:'/fsxt/sysBase!getAirport.action'
                },
                autoLoad: true,
                listeners:{
                    load:function(){
                        var insert = Ext.create('commonModel',{value:'',label:'0-全部'});
                        this.insert(0,insert);
                    }
                }
            })
        });

        var store = Ext.create('Ext.data.Store', {
            model: 'Instruction',
            pageSize:20,
            proxy: {
                type:'ajax',
                url:'/fsxt/instruction/instruction!getInstruction.action',
                reader: {
                    root: 'root',
                    totalProperty: 'totalProperty'
                }
            },
            autoLoad: true,
            listeners:{
                beforeload:function(){
                    store.proxy.extraParams = {
                        no:no.getValue(),
                        customerId:customerCombo.getValue(),
                        startAirportId:startAirport.getValue(),
                        endAirportId:endAirport.getValue()
                    }
                }
            }
        });

        var grid = Ext.create('Ext.grid.Panel', {
            title: '委托单列表',
            store: store,
            height: '100%',
            width: '100%',
            loadMask: true,
            autoScroll:true,
            columns:[
                Ext.create('Ext.grid.RowNumberer'),
                {text: "单号",dataIndex: 'no',sortable: true,width:120},
                {text: "委托内容",dataIndex: 'contentName',sortable: true,width:85},
                {text: "客户",dataIndex: 'customerName',sortable: true},
                {text: "起始港口",dataIndex: 'startAirportName',sortable: true},
                {text: "目的港口",dataIndex: 'endAirportName',sortable: true},
                {text: "货物",dataIndex: 'cargoName',sortable: true},
                {text: "数量",dataIndex: 'num',sortable: true,width:70,renderer:function(value,cellmeta,record){return value+record.get('unitName')}},
                {text: "体积",dataIndex: 'volume',sortable: true,width:70},
                {text: "重量",dataIndex: 'weight',sortable: true,width:70},
                {text: "尺寸描述",dataIndex: 'sizeDesc',sortable: true,width:120},
                {text: "入库方式",dataIndex: 'depotInName',sortable: true},
                {text: "入库时间",dataIndex: 'depotInDesc',sortable: true},
                {text: "航班",dataIndex: 'flight',sortable: true},
                {text: "航班时间",dataIndex: 'flightDateStr',sortable: true},
                {text: "报关方法",dataIndex: 'flagName',sortable: true},
                {text: "报关时间",dataIndex: 'bgDateStr',sortable: true},
                {text: "创建者",dataIndex: 'creatorName',sortable: true,width:70},
                {text: "创建时间",dataIndex: 'createDateStr',sortable: true},
                {text: "备注",dataIndex: 'remark',sortable: true}
            ],
            tbar:Ext.create('Ext.toolbar.Toolbar',{
                items:['-',{
                    xtype:'label',
                    text:'单号:'
                },no,'-',{
                    xtype:'label',
                    text:'委托人'
                },customerCombo,'-',{
                    xtype:'label',
                    text:'起始港'
                },startAirport,'-',{
                    xtype:'label',
                    text:'目的港'
                },endAirport,'-',{
                    xtype:'button',
                    iconCls:'find',
                    text:'查询',
                    handler:function(){
                        store.loadPage(1);
                    }
                },'-','->','-',{
                    xtype:'button',
                    iconCls:'create',
                    id:'createButton',
                    text:'新建',
                    handler:function(b,e){
                        location.href = '/fsxt/instruction/instruction.action';
                    }
                },'-',{
                    xtype:'button',
                    iconCls:'update',
                    text:'修改',
                    id:'updateButton',
                    handler:function(b,e){

                    }
                },'-',{
                    xtype:'button',
                    iconCls:'search',
                    text:'详细',
                    handler:function(){
                        var selected = grid.getView().getSelectionModel().getSelection();
                        if(selected.length == 0){
                            Ext.Msg.show({title:'提示',msg:'请选择要查看记录',icon:Ext.Msg.WARNING,buttons:Ext.Msg.OK});
                            return;
                        }
                        var record = selected[0];
                        window.open('/fsxt/instruction/instruction!showDetail.action?id='+record.get('id'));
                    }
                },'-']
            }),
            bbar: Ext.create('Ext.PagingToolbar', {
                store: store,
                displayInfo: true,
                displayMsg: '当前第 {0} - {1} 条记录,共 {2} 条',
                emptyMsg: "没有委托单记录"
            }),
            renderTo:Ext.getBody()
        });

    });
})();
</script>
</head>
<body>
</body>
</html>